package com.zhonglz.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhonglz.commons.base.BaseService;
import com.zhonglz.model.BuSignInfo;
import com.zhonglz.model.SysFileInfo;
import com.zhonglz.service.BuSignInfoService;
import com.zhonglz.util.result.ResultUtils;
import com.zhonglz.util.tools.ObjectUtils;
import com.zhonglz.util.tools.UuidUtils;

@Service
@Transactional 
public class BuSignInfoServiceImpl extends BaseService implements BuSignInfoService {

	
	@Override
	public ResultUtils saveInfo(BuSignInfo buSignInfo) {
		if(ObjectUtils.isEmpty(buSignInfo)) { 
			return new ResultUtils(ResultUtils.CODE_ERROR, "没有数据需要保存！");
		}
		if(ObjectUtils.isNotEmpty(buSignInfo.getSignId())) {
			int count = buSignInfoMapper.updateByPrimaryKeySelective(buSignInfo);
			if(count>0) {
				return new ResultUtils(ResultUtils.CODE_SUCCESS, "修改信息成功");
			}else {
				return new ResultUtils(ResultUtils.CODE_ERROR, "修改信息失败");
			}
		}else {
			String uuid=UuidUtils.uuid();
			buSignInfo.setSignBackFileId(buSignInfo.getSignFrontFileId());
			buSignInfo.setSignId(uuid);
			buSignInfo.setCreateTime(new Date());
			int count = buSignInfoMapper.insertSelective(buSignInfo);
			
			if(count>0) {
				return new ResultUtils(ResultUtils.CODE_SUCCESS, "新增信息成功");
			}else {
				return new ResultUtils(ResultUtils.CODE_ERROR, "新增信息失败");
			}
		}
	}

	@Override
	public List<BuSignInfo> selectByList(Map<String, Object> mapParam) {
		return buSignInfoMapper.selectByList(mapParam);
	}

	@Override
	public BuSignInfo selectInfoById(String id) {
		return buSignInfoMapper.selectByPrimaryKey(id);	
	}

}
